package com.ruoyi.hr.controller.hr.contractmanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.CompanysService;
import com.ruoyi.hr.service.contractmanage.NewSignService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @author zeo
 * @explain 合同新签登记
 * @date 2020/3/23
 */
@Controller
@RequestMapping("/contractManage/newSign")
public class NewSignController extends BaseController {

    @Autowired
    NewSignService newSignService;

    @Autowired
    AuthorityService authorityService;


    private String prefix = "hr/contractmanage/newsign";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String newSign() {
        return prefix + "/newSign";
    }

    /**
     * 获取数据集合
     *
     * @param map
     * @return
     */
    @RequestMapping("/findDataList")
    @ResponseBody
    public TableDataInfo findDataList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(newSignService.findDataList(map, authority));
    }

    @GetMapping("/addEmp")
    public String addEmp() {
        return prefix + "/addEmp";
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Map map = newSignService.findDataById(id);
        mmap.put("emp", map);
        //公司
        mmap.put("companys", newSignService.findComp());
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(newSignService.editData(map));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(newSignService.remove(ids));
    }

}
